package com.woniuxy.rms.controller;

import com.github.pagehelper.PageInfo;
import com.woniuxy.rms.advice.LogPoint;
import com.woniuxy.rms.pojo.Goods;
import com.woniuxy.rms.service.GoodsService;
import com.woniuxy.rms.util.DataResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Auther: ChenGang  <br/>
 * Date: 2020/3/27 0027:下午 10:14  <br/>
 * Description:商品控制层
 */
@Controller
@RequestMapping("/goods")
public class GoodsController {

    @Autowired
    GoodsService goodsService;
    /**
     * Description : 加载商品列表  <br/>
     * ChangeLog : 1. 创建 (2020/3/28 0028 上午 9:56 [Administrator]);
     * @param currentPage 当前页
     * @param pageSize 页大小
     * @param title 商品名称
     * @param goodsType  商品类型
     * @param status   审核状态
     * @return com.woniuxy.rms.util.DataResult
    */
    @GetMapping("/list")
    @ResponseBody
    @LogPoint("查询商品列表")
    public DataResult goodsList(@RequestParam(defaultValue = "1",required = false,name = "page") Integer currentPage,
                                @RequestParam(defaultValue = "10",required = false,name = "limit") Integer pageSize,
                                @RequestParam(required = false) String title,
                                @RequestParam(required = false) String goodsType,
                                @RequestParam(required = false) Integer status){
            List<Goods> goods = goodsService.findByPage(currentPage,pageSize,title,goodsType,status);
            PageInfo info = new PageInfo(goods);
            return DataResult.success(info);
    }
    /**
     * Description : 审核商品  <br/>
     * ChangeLog : 1. 创建 (2020/3/27 0027 下午 10:47 [Administrator]);
     * @param id
     * @param status
     * @return com.woniuxy.rms.util.DataResult
    */
    @PutMapping("/goodsStatus")
    @ResponseBody
    @LogPoint("商品审核")
    public DataResult goodsStatus(Long id,Integer status){
        return goodsService.goodsStatus(id,status);
    }
}